/***********************************************************************
filename: 	HgeSingleton.h
created:	22/2/2004
author:		Paul D Turner

purpose:	Singleton Base Class

Copyright (C) Scott Bilas, 2000.
All rights reserved worldwide.

This software is provided "as is" without express or implied
warranties. You may freely copy and compile this source into
applications you distribute provided that the copyright text
below is included in the resulting source code, for example:
"Portions Copyright (C) Scott Bilas, 2000"
*************************************************************************/

/*************************************************************************
The code in this file is taken from article 1.3 in the the book:
Game Programming Gems from Charles River Media
*************************************************************************/
#ifndef _HgeSingleton_h_
#define _HgeSingleton_h_

#include "hgeForwardRef.h"
#include <cassert>

template <typename T> class Singleton
{
protected:
	static T* ms_Singleton;

public:
	Singleton( void )
	{
		ms_Singleton = static_cast<T*>(this);
	}
	~Singleton( void )
	{  ms_Singleton = 0;  }
	static T& getSingleton( void )
	{  return ( *ms_Singleton );  }
	static T* getSingletonPtr( void )
	{  return ( ms_Singleton );  }

private:
	Singleton& operator=(const Singleton&) { return this; }
	Singleton(const Singleton&) {}
};

#endif	// end of guard _HgeSingleton_h_
